package org.example.struct.array;

import org.example.node.ListNode;

/**
 * @author liyishan
 * @date 2024/9/5 11:01
 * @apiNote
 */

public class M0207GetIntersectionNode {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA == null || headB == null){
            return null;
        }
        ListNode pA = headA,pB = headB;
        while(pA != pB){
            pA = pA == null? headB : pA.next;
            pB = pB == null? headA : pB.next;
        }
        return pA;
    }
}
